<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>多级菜单</title>
	<link href="../static/css/main_css.css" rel="stylesheet" type="text/css" />
	<link href="../static/css/zTreeStyle.css" rel="stylesheet" type="text/css">
	<script type="text/javascript" src="../static/js/jquery-1.7.1.js"></script>
	<script type="text/javascript" src="../static/js/jquery.ztree.core-3.2.js"></script>
	<script type="text/javascript" src="../static/js/commonAll.js"></script>
	<script type="text/javascript">
		/* zTree插件加载目录的处理  */
		var zTree;
		var setting = {
				view: {
					dblClickExpand: false,
					showLine: false,
					expandSpeed: ($.browser.msie && parseInt($.browser.version)<=6)?"":"fast"
				},
				data: {
					key: {
						name: "resourceName"
					},
					simpleData: {
						enable:true,
						idKey: "resourceID",
						pIdKey: "parentID",
						rootPId: ""
					}
				},
				callback: {
					onClick: zTreeOnClick			
				}
		};
		 
		var curExpandNode = null;
		function beforeExpand(treeId, treeNode) {
			var pNode = curExpandNode ? curExpandNode.getParentNode():null;
			var treeNodeP = treeNode.parentTId ? treeNode.getParentNode():null;
			for(var i=0, l=!treeNodeP ? 0:treeNodeP.children.length; i<l; i++ ) {
				if (treeNode !== treeNodeP.children[i]) {
					zTree.expandNode(treeNodeP.children[i], false);
				}
			}
			while (pNode) {
				if (pNode === treeNode) {
					break;
				}
				pNode = pNode.getParentNode();
			}
			if (!pNode) {
				singlePath(treeNode);
			}
	
		}
		function singlePath(newNode) {
			if (newNode === curExpandNode) return;
			if (curExpandNode && curExpandNode.open==true) {
				if (newNode.parentTId === curExpandNode.parentTId) {
					zTree.expandNode(curExpandNode, false);
				} else {
					var newParents = [];
					while (newNode) {
						newNode = newNode.getParentNode();
						if (newNode === curExpandNode) {
							newParents = null;
							break;
						} else if (newNode) {
							newParents.push(newNode);
						}
					}
					if (newParents!=null) {
						var oldNode = curExpandNode;
						var oldParents = [];
						while (oldNode) {
							oldNode = oldNode.getParentNode();
							if (oldNode) {
								oldParents.push(oldNode);
							}
						}
						if (newParents.length>0) {
							for (var i = Math.min(newParents.length, oldParents.length)-1; i>=0; i--) {
								if (newParents[i] !== oldParents[i]) {
									zTree.expandNode(oldParents[i], false);
									break;
								}
							}
						}else {
							zTree.expandNode(oldParents[oldParents.length-1], false);
						}
					}
				}
			}
			curExpandNode = newNode;
		}
	
		function onExpand(event, treeId, treeNode) {
			curExpandNode = treeNode;
		}
		
		/** 用于捕获节点被点击的事件回调函数  **/
		function zTreeOnClick(event, treeId, treeNode) {
			var zTree = $.fn.zTree.getZTreeObj("dleft_tab1");
			zTree.expandNode(treeNode, null, null, null, true);
			// 如果节点路径为空或者为"#"，不允许单击操作
			if(treeNode.accessPath=="" || treeNode.accessPath=="#"){
				//alert("节点路径为空或者为'#'哦...");
				return false;
			}
			 //  弹出点击的超连接的id；
			//alert(treeNode.resourceCode);
			 //  根据id。来给地址
	
				 //treeNode.accessPath="/bsc/systemdept/listAll?code="+resourceCode;
		    // 跳到该节点下对应的路径, 把当前资源ID(resourceID)传到后台，写进Session
		    rightMain(treeNode.accessPath);
		};
		
		$(document).ready(function(){
	            	 $(document).ajaxStart(onStart).ajaxSuccess(onStop);
	     			/** 默认异步加载"业务模块"目录  **/
	     			loadMenu('YEWUMOKUAI', "dleft_tab1");
	     			// 默认展开所有节点
	     			if( zTree ){
	     				// 默认展开所有节点
	     				zTree.expandAll(true); 
	     			}
	                        
		});
		
		function loadMenu(resourceType, treeObj){ // parentID上一级节点   "resourceGrade":2,排列顺序   "resourceID":2,个人id
   /*  data = [{"accessPath":"","checked":false,"parentID":1,"resourceGrade":3,"resourceID":3,"resourceName":"基础数据"},
            {"accessPath":"changepwd.html","checked":false,"parentID":3,"resourceGrade":3,"resourceID":8,"resourceName":"承租方管理"},
            {"accessPath":"login.html","checked":false,"parentID":3,"resourceGrade":3,"resourceID":32,"resourceName":"家庭成员管理"},
            {"accessPath":"newsAdd.html","checked":false,"parentID":3,"resourceGrade":3,"resourceID":39,"resourceName":"施工单位管理"},
            
            {"accessPath":"table.html","checked":false,"parentID":1,"resourceGrade":1,"resourceID":2,"resourceName":"摇号配租"},
            {"accessPath":"","checked":false,"parentID":2,"resourceGrade":3,"resourceID":5,"resourceName":"房源导出"},
            {"accessPath":"","checked":false,"parentID":2,"resourceGrade":3,"resourceID":6,"resourceName":"租户导出"}
           ]; */
           //data=${json};
            // 如果返回数据不为空，加载"业务模块"目录
            /* if(data != null){
                // 将返回的数据赋给zTree
                $.fn.zTree.init($("#"+treeObj), setting, data);
//              alert(treeObj);
                zTree = $.fn.zTree.getZTreeObj(treeObj);
                if( zTree ){
                    // 默认展开所有节点
                    zTree.expandAll(true);
                }
            } */
            $.ajax({
	             type: "post",
	             url: "${jsonurl}",
	             dataType: "json",
	             success: function(data){
	            	 console.log(data);
					// 如果返回数据不为空，加载"业务模块"目录
					if(data != null){
						// 将返回的数据赋给zTree
						$.fn.zTree.init($("#"+treeObj), setting, data);
 						//alert(treeObj);
						zTree = $.fn.zTree.getZTreeObj(treeObj);
						if( zTree ){
							// 默认展开所有节点
							zTree.expandAll(false);
						}
					}
				}
			});
		}
		
		function onStart(){ //加载树形菜单 
			$("#ajaxDialog").show();
		}
		function onStop(){//加载树形菜单 
			$("#ajaxDialog").hide();
		}
	</script>
</head>
<body>
	    <!-- 左侧菜单 -->
		 <div id="left_menu_cnt">
		 	<div id="nav_module">
		 		<img src="../static/images/module_2.png" width="170" height="58"/>
		 	</div>
		 	<!-- 动态生成的菜单 -->
		 	<div id="nav_resource">
		 		<ul id="dleft_tab1" class="ztree"></ul>
		 	</div>
		 </div>
	
	<!-- 右侧页面 -->
    <div id="top_nav">
	 	<!--<span id="here_area">当前位置：系统管理&nbsp;>&nbsp;</span>-->
	</div>
    <div id="main">
      	<iframe name="right" id="rightMain" src="${url }" frameborder="no" scrolling="auto" width="100%" height="100%" allowtransparency="true"/>
    </div>
</body>
</html>